package com.lyf.scm.plan.domain.repository;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.plan.api.dto.GmvTargetDTO;
import com.lyf.scm.plan.api.dto.PartOfGmvTargetInfo;
import com.lyf.scm.plan.domain.convertor.GmvTargetConvertor;
import com.lyf.scm.plan.domain.convertor.GmvTargetSelectConvertor;
import com.lyf.scm.plan.insfrastructure.db.dataobject.DemandPlanDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.GmvTargetDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.SalesPlanSelectDO;
import com.lyf.scm.plan.insfrastructure.db.mapper.GmvTargetMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 * gmv指标资源库
 *
 * @author: haodong
 * @data: 2020/7/8 16:49
 */
@Service
public class GmvTargetRepository {

    @Resource
    private GmvTargetConvertor gmvTargetConvertor;
    @Resource
    private GmvTargetSelectConvertor gmvTargetSelectConvertor;
    @Resource
    private GmvTargetMapper gmvTargetMapper;

    // /**
    //  * 按条件分页查询gmv指标(天)
    //  *
    //  * @param gmvTarget
    //  * @return
    //  */
    // public PageInfo<com.lyf.scm.plan.api.dto.GmvTargetDTO> listPageBySelective(com.lyf.scm.plan.api.dto.GmvTargetDTO gmvTarget) {
    //     PageInfo<GmvTargetDTO> pageInfo = PageHelper.startPage(gmvTarget.getPageNum(), gmvTarget.getPageSize()).doSelectPageInfo(() ->
    //             gmvTargetDayMapper.listPageBySelective(gmvTargetSelectConvertor.dtoToDO(gmvTarget)));
    //     return gmvTargetDayConvertor.doToDTO(pageInfo);
    // }
    //
    // /**
    //  * 根据分页后的条件查询gmv指标(天)
    //  * @param selective
    //  * @return
    //  */
    // public List<com.lyf.scm.plan.api.dto.GmvTargetDTO> listBySelective(com.lyf.scm.plan.api.dto.GmvTargetDTO selective) {
    //     return gmvTargetDayConvertor.doToDTO(gmvTargetDayMapper.listBySelective(gmvTargetSelectConvertor.dtoToDO(selective)));
    // }

    /**
     * 按条件分页查询gmv指标
     *
     * @param gmvTarget
     * @return
     */
    public PageInfo<GmvTargetDTO> listPageBySelective(GmvTargetDTO gmvTarget) {
        PageInfo<GmvTargetDO> pageInfo = PageHelper.startPage(gmvTarget.getPageNum(),gmvTarget.getPageSize()).doSelectPageInfo(
                ()->gmvTargetMapper.listPageBySelective(gmvTargetSelectConvertor.dtoToDO(gmvTarget)));
        return gmvTargetConvertor.doToDTO(pageInfo);
    }

    /**
     * 根据分页后的参数查询
     * @param gmvTarget
     * @return
     */
    public List<GmvTargetDTO> listBySelective(GmvTargetDTO gmvTarget) {
        return gmvTargetConvertor.doToDTO(gmvTargetMapper.listBySelective(gmvTargetConvertor.dtoToDO(gmvTarget)));
    }

    /**
     * 查询全渠道gmv指标
     *
     * @param gmvTarget
     * @return
     */
    public List<GmvTargetDTO> listAllByCycles(GmvTargetDTO gmvTarget) {
        return gmvTargetConvertor.doToDTO(gmvTargetMapper.listAllBySelective(gmvTargetSelectConvertor.dtoToDO(gmvTarget)));
    }

    /**
     * 批量新增
     *
     * @param gmvTargetList
     * @return
     */
    public Integer batchSave(List<GmvTargetDTO> gmvTargetList) {
        return gmvTargetMapper.batchSave(gmvTargetConvertor.dtoToDO(gmvTargetList));

    }

    /**
     * 多条件批量查询
     *
     * @param gmvTargetList
     * @param ifTrue
     * @return
     */
    public List<GmvTargetDTO> listByBatch(List<GmvTargetDTO> gmvTargetList, boolean ifTrue) {
        return gmvTargetConvertor.doToDTO(gmvTargetMapper.listByBatch(gmvTargetConvertor.dtoToDO(gmvTargetList), ifTrue));
    }

    /**
     * 批量更新
     *
     * @param intersection
     * @return
     */
    public Integer batchUpdate(List<GmvTargetDTO> intersection) {
        return gmvTargetMapper.batchUpdate(gmvTargetConvertor.dtoToDO(intersection));
    }

    public List<PartOfGmvTargetInfo> listPartBySelective(SalesPlanSelectDO salesPlanSelectDO) {
        return gmvTargetMapper.listPartBySelective(salesPlanSelectDO);
    }
    public List<PartOfGmvTargetInfo> listPartBySelectiveCharts(SalesPlanSelectDO salesPlanSelectDO) {
        return gmvTargetMapper.listPartBySelectiveCharts(salesPlanSelectDO);
    }

    /**
     * 根据id集合查询
     * @param idList
     * @return
     */
    public List<GmvTargetDTO> listByIdList(List<Long> idList) {
        return gmvTargetConvertor.doToDTO(gmvTargetMapper.listByIdList(idList));
    }

    public List<GmvTargetDTO> listSaleTarget(DemandPlanDO demandPlanDO) {
        return gmvTargetConvertor.doToDTO(gmvTargetMapper.listSaleTarget(demandPlanDO));
    }

    public void delete(String opSign){
        gmvTargetMapper.delete(opSign);
    }

    public void deleteByOpSign(String opSign) {
        gmvTargetMapper.deleteByOpSign(opSign);
    }
}
